package com.maochang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maochang.pojo.PsInspectiontaskDetail;
import com.maochang.pojo.PsInspectiontaskMain;
import com.maochang.pojo.PsPoleInfo;
import com.maochang.pojo.PsSystemconfig;
import com.maochang.pojo.util.Result;
import com.maochang.pojo.util.Result1;
import com.maochang.pojo.util.ResultDT;
import com.maochang.service.XunJianRenWuZhiXingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/XunJianZhiXing")
public class XunJianRenWuZhiXingHuiZhi {

    @Resource
    private XunJianRenWuZhiXingService xunJianRenWuZhiXingService;


    @GetMapping("/XunJian")
    public ModelAndView index(Model model){
        return new ModelAndView("xunjianguanli/xunjianyuan/XunJianRenWuZhiXingHuiZhi");
    }

    /**
     * 分页加查询
     * */
    @GetMapping("/XunJianCha")
    public Result1 ChaJson(PsInspectiontaskMain aa, String kai, String jie, @RequestParam("page") int current, @RequestParam("limit") int size, HttpSession session){
        Page<PsInspectiontaskMain> PsInList= xunJianRenWuZhiXingService.ChaXjZhiXing(aa,kai,jie,current,size,session);
        return Result1.success1(PsInList);
    }

    /**
     * 下拉框
     * */
    @GetMapping("/XiaLaKuang")
    public List<PsSystemconfig> ChaXia(){
        return xunJianRenWuZhiXingService.ChaXia();
    }

    /**
     * 线路管理
     * @param lineName
     * @return
     */
    @GetMapping("/xianlu")
    public  ResultDT ChaXianlU(String lineName){
        ResultDT  aa=xunJianRenWuZhiXingService.ChaXina(lineName);
        return aa;
    }

    /***
     * 回执点击左边给右边的input框赋值
     * */
    @GetMapping("/ChaXianLu")
    public PsPoleInfo ChaXiaLuMing(PsPoleInfo psPoleInfo){
        System.out.println(psPoleInfo+"线路名称");
        return xunJianRenWuZhiXingService.ChaLu(psPoleInfo);
    }

    /**
     * 回执缺陷类型下拉查询
     * */
    @GetMapping("/QueLeiXia")
    public List<PsSystemconfig> ChaQueLei(){
        return xunJianRenWuZhiXingService.ChaQueLei();
    }
    /**
     * 回执缺陷级别下拉查询
     * */
    @GetMapping("/ChaQueJi")
    public List<PsSystemconfig> ChaQueJi(){
        return xunJianRenWuZhiXingService.ChaQueJi();
    }

    /**
     * 子表新增
     * */
    @PostMapping("/ziBiaoXinZeng")
    public Result ZiBiaoXin(PsInspectiontaskDetail psInspectiontaskDetail){
        String aa= xunJianRenWuZhiXingService.addPsIt(psInspectiontaskDetail);
        System.out.println(aa);
        Result ak=new Result();
        ak.setMsg(aa);
        return ak;
    }

    /**
     * 回执死值修改状态
     * */
    @PostMapping("/SiXiuZhuang")
    public Result SiXiuZhuang(PsInspectiontaskMain id){
        xunJianRenWuZhiXingService.SiZhiXiu(id);
        return Result.success("修改成功");
    }
    /***
     * 查看点击左边给右边的input框赋值
     * */
    @GetMapping("/ChaKanLu")
    public PsInspectiontaskDetail ChaXiaLuMing(PsInspectiontaskDetail psPoleInfo){
        System.out.println(psPoleInfo+"线路名称");
        System.out.println(psPoleInfo.getTaskId()+"aaa");
        return xunJianRenWuZhiXingService.ChaKanLu(psPoleInfo);
    }

    /**
     * 执行死值修改状态
     * */
    @PostMapping("/ZhiSiXiuZhuang")
    public Result ZhiSiXiuZhuang(PsInspectiontaskMain id){
        xunJianRenWuZhiXingService.ZhiSiZhiXiu(id);
        return Result.success("修改成功");
    }


    /**
     * 时间死值修改状态
     * */
    @PostMapping("/ShiJianSiXiuZhuang")
    public Result ShiJianSiXiuZhuang(PsInspectiontaskMain id){
        xunJianRenWuZhiXingService.ShiJianSiZhiXiu(id);
        return Result.success("修改成功");
    }
   /**
    * 操作修改
    * */
   @PostMapping("/CaoXiu")
   public Result CaoXiu(PsInspectiontaskDetail psInspectiontaskDetail){
       Result result =new Result();
       boolean fAlg=xunJianRenWuZhiXingService.CaoZuoXiuGai(psInspectiontaskDetail);
       if(fAlg==true){
           result.setMsg("修改成功");
       }
       return result;
   }

}
